// Define fetchWrapper function
const timeout = 10000
const request = async ({ url, options }) => {
  // Part 1: Add headers and attach auth token
  // const headers = new Headers(options.headers || {})
  let controller = new AbortController()
  let signal = controller.signal
  // Part 2: Fetch sends the request
  setTimeout(() => {
    controller.abort()
  }, timeout)
  try {
    const response = await fetch(url, {
      ...options,
      signal: signal,
    })
    // Part 3: Handle the received response
    if (response.ok) {
      const data = await response.json()
      return { data: data }
    } else {
      throw response
    }
  } catch (err) {
    return Promise.reject(err)
  }
}
export default request
